﻿Imports System.Data.OleDb
Public Class NhanVienDAO
    Public Function Insert(ByVal tmp As NhanVienDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into NHANVIEN (HoTenNV, CMND, NgaySinh, GioiTinh, DiaChi, DienThoai, MaChucVu, MatKhau) values (@HoTenNV, @CMND, @NgaySinh, @GioiTinh, @DiaChi, @DienThoai, @MaChucVu, @MatKhau)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4, para5, para6, para7, para8 As OleDbParameter
        para1 = New OleDbParameter("@HoTenNV", tmp.HoTenNV)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@CMND", tmp.CMND)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@NgaySinh", tmp.NgaySinh)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@GioiTinh", tmp.GioiTinh)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@DiaChi", tmp.DiaChi)
        cmd.Parameters.Add(para5)
        para6 = New OleDbParameter("@DienThoai", tmp.DienThoai)
        cmd.Parameters.Add(para6)
        para7 = New OleDbParameter("@MaChucVu", tmp.MaChucVu)
        cmd.Parameters.Add(para7)
        para8 = New OleDbParameter("@MatKhau", tmp.MatKhau)
        cmd.Parameters.Add(para8)
        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result

        'Dim cn As OleDbConnection = DataProvider.ConnectionData()
        'Dim str As String = "insert into NHANVIEN (HoTenNV, CMND, NgaySinh, GioiTinh, DiaChi, DienThoai, MaChucVu, MatKhau) values (@HoTenNV, @CMND,@NgaySinh, @GioiTinh, @DiaChi, @DienThoai, @MaChucVu, @MatKhau)"
        'Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        'cmd.CommandType = CommandType.Text
        'Dim pr() As OleDbParameter = {New OleDbParameter("@HoTenNV", tmp.HoTenNV), _
        '                              New OleDbParameter("@CMND", tmp.CMND), _
        '                              New OleDbParameter("@NgaySinh", tmp.NgaySinh), _
        '                              New OleDbParameter("@GioiTinh", tmp.GioiTinh), _
        '                              New OleDbParameter("@DiaChi", tmp.DiaChi), _
        '                              New OleDbParameter("@DienThoai", tmp.DienThoai), _
        '                              New OleDbParameter("@MaChucVu", tmp.MaChucVu), _
        '                              New OleDbParameter("@MatKhau", tmp.MatKhau)}
        'For _i As Integer = 0 To pr.Length() - 1
        '    cmd.Parameters.Add(pr(_i))
        'Next
        ''Dim _str As String = String.Format("insert into NHANVIEN (HoTenNV, CMND, NgaySinh, GioiTinh, DiaChi, DienThoai, MaChucVu, MatKhau) values ({0},{1}, {2}, {3}, {4}, {5}, {6}, {7})", tmp.HoTenNV, tmp.CMND, tmp.NgaySinh, tmp.GioiTinh, tmp.DiaChi, tmp.DiaChi, tmp.MaChucVu, tmp.MatKhau)

        ''Dim cmd As OleDbCommand = New OleDbCommand(_str, cn)
        '' cmd.CommandType = CommandType.Text
        'Dim result As Integer = cmd.ExecuteNonQuery()
        'cn.Close()
        'Return result
    End Function

    Public Function Update(ByVal tmp As NhanVienDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "update NHANVIEN set HoTenNV=@HoTenNV, CMND=@CMND,NgaySinh=@NgaySinh,GioiTinh=@GioiTinh,DiaChi=@DiaChi,DienThoai=@DienThoai,MaChucVu=@MaChucVu,MatKhau=@MatKhau where MaNV=@MaNhanVien"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4, para5, para6, para7, para8, para9 As OleDbParameter
        
        para2 = New OleDbParameter("@HoTenNV", tmp.HoTenNV)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@CMND", tmp.CMND)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@NgaySinh", tmp.NgaySinh)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@GioiTinh", tmp.GioiTinh)
        cmd.Parameters.Add(para5)
        para6 = New OleDbParameter("@DiaChi", tmp.DiaChi)
        cmd.Parameters.Add(para6)
        para7 = New OleDbParameter("@DienThoai", tmp.DienThoai)
        cmd.Parameters.Add(para7)
        para8 = New OleDbParameter("@MaChucVu", tmp.MaChucVu)
        cmd.Parameters.Add(para8)
        para9 = New OleDbParameter("@MatKhau", tmp.MatKhau)
        cmd.Parameters.Add(para9)
        para1 = New OleDbParameter("@MaNhanVien", Integer.Parse(tmp.MaNhanVien))
        cmd.Parameters.Add(para1)
        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As NhanVienDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from NHANVIEN where MaNV=@MaNhanVien"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@MaNhanVien", tmp.MaNhanVien)
        cmd.Parameters.Add(para1)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function
    Public Function GetTable(ByVal t As String) As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = t
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function
    Public Function GetValue(ByVal t As String) As String
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = t
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        Dim kq As String = cmd.ExecuteScalar()
        Return kq
    End Function
End Class
